package net.studou.convert;

import java.util.Date;
import java.util.Set;

import net.studou.bean.tools.IConvert;
import net.studou.po.Popedom;
import net.studou.po.UserPopedom;
import net.studou.tools.Utils;

public class VIPConvert implements IConvert {


	@SuppressWarnings("unchecked")
	public Object convert(Object value) throws Exception {
		Set<UserPopedom> userPopedoms = (Set<UserPopedom>) value;
		boolean vip = false;
		UserPopedom userPopedom = null;
		for (UserPopedom up : userPopedoms) {
			Popedom popedom = up.getPopedom();
			String popedomCd = popedom.getPopedomCode();
			if(popedomCd.contains("vip")){
				vip = true;
				userPopedom = up;
			} 
		}
		
		if(!vip){
			value = "你不是VIP";
		} else {
			int status = userPopedom.getStatus().intValue();
			if(status == 2){
				value = "您的VIP权限已经失效";
			} else {
				Date date = userPopedom.getEndTime();
				if(date.compareTo(Utils.getChinaDateTime()) > 0){
					value = Utils.NORMAL_2_YEAR.format(date);
				} else {
					value = "您的VIP权限已经到期";
				}
			}
		}
		return value;
	}
}
